package com.example.administrator.tiyuapp;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.administrator.tiyuapp.EventFragment.EventFragment;
import com.example.administrator.tiyuapp.HeaderFragment.HeaderFragment;
import com.example.administrator.tiyuapp.NewsFragment.NewsFragment;


public class MainActivity extends AppCompatActivity {

    private RadioGroup radioGroup;
    private FragmentManager fragmentManager;
    private TextView textView;
    private RadioGroup topRadioGroup;
    private LinearLayout matchHeaderlayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        rgEvent();//点击事件处理
        fragmentManager=getSupportFragmentManager();

    }
    //点击事件处理
    private void rgEvent() {
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (radioGroup.getCheckedRadioButtonId()) {
                    case R.id.activity_main_rb_news:
                        //新闻
                        textView.setVisibility(View.VISIBLE);
                        topRadioGroup.setVisibility(View.GONE);
                        matchHeaderlayout.setVisibility(View.GONE);
                        FragmentTransaction fragmentTransaction1 = fragmentManager.beginTransaction();
                        fragmentTransaction1.replace(R.id.acitivity_main_fragment,new NewsFragment());
                        fragmentTransaction1.commit();
                        break;
                    case R.id.activity_main_rb_header:
                        //头条
                        textView.setVisibility(View.GONE);
                        topRadioGroup.setVisibility(View.VISIBLE);
                        matchHeaderlayout.setVisibility(View.GONE);
                        FragmentTransaction fragmentTransaction2 = fragmentManager.beginTransaction();
                        fragmentTransaction2.replace(R.id.acitivity_main_fragment,new HeaderFragment());
                        fragmentTransaction2.commit();

                        break;
                    case R.id.activity_main_rb_event:
                        textView.setVisibility(View.GONE);
                        topRadioGroup.setVisibility(View.GONE);
                        matchHeaderlayout.setVisibility(View.VISIBLE);
                        FragmentTransaction fragmentTransaction3 = fragmentManager.beginTransaction();
                        fragmentTransaction3.replace(R.id.acitivity_main_fragment,new EventFragment());
                        fragmentTransaction3.commit();

                        //赛事
                        break;
                }


            }
        });
    }

    /**
     * 初始化控件
     */
    private void initView() {
        radioGroup = (RadioGroup) findViewById(R.id.activity_main_rg);
        textView = (TextView) findViewById(R.id.news_title);
        topRadioGroup = (RadioGroup) findViewById(R.id.topRadioGroup);
        matchHeaderlayout = (LinearLayout) findViewById(R.id.LinearLayout_matchheader);
    }
}
